from PySide2.QtWidgets import QComboBox, QStackedWidget, QVBoxLayout, QHBoxLayout, QWidget, QFrame
from PySide2.QtCore import Qt

from .ui_calc.page1 import Page1
from .ui_calc.page2 import Page2
from .ui_calc.page3 import Page3
from .ui_calc.page4 import Page4

from .form.widget_simple_ui import Ui_formSimple as FormSimple


class WidgetCalc(QWidget, FormSimple):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.labelTitleSimple.setText('角差计算程序、A点预测程序')
        self.labelTitleSimple.setStyleSheet('font-size:16pt; font-weight:600;')

        # 创建下拉菜单
        self.combo = QComboBox()
        self.combo.addItems(["夹角公式上倾井", "夹角公式下倾井", "预测垂深公式上倾井", "预测垂深公式下倾井"])
        self.combo.currentIndexChanged.connect(self.on_combobox_changed)

        # 创建堆栈容器
        self.stacked_widget = QStackedWidget()

        # 修改页面创建方式
        self.pages = [
            Page1(),
            Page2(),
            Page3(),
            Page4()
        ]
        for page in self.pages:
            self.stacked_widget.addWidget(page)

        # 总布局
        body_frame = QFrame(self.widgetSimple)
        body_frame.setFixedSize(400, 320)  # 设置固定大小
        body_frame.setFrameShape(QFrame.StyledPanel)  # 可选：添加边框样式

        # 主布局使用水平布局来实现水平居中
        main_layout = QHBoxLayout(self.widgetSimple)
        main_layout.addStretch()  # 左侧弹性空间
        main_layout.addWidget(body_frame, 0, Qt.AlignTop)  # 添加frame并顶部对齐
        main_layout.addStretch()  # 右侧弹性空间

        # body_frame内部布局
        layout_body_frame = QVBoxLayout(body_frame)
        layout_body_frame.addWidget(self.combo)
        layout_body_frame.addWidget(self.stacked_widget)

    def on_combobox_changed(self, index):
        self.stacked_widget.setCurrentIndex(index)
